<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml">
<head th:include="/common/head::head('编辑用户 - 广告机管理后台')"></head>
<!--/* <editor-fold desc="define"> */-->
<!--/*@thymesVar id="adminPath" type="java.lang.String"*/-->
<!--/*@thymesVar id="adminRoleID" type="java.lang.Integer"*/-->
<!--/*@thymesVar id="newEntityID" type="java.lang.Integer"*/-->
<!--/*@thymesVar id="loginUser" type="com.xmlan.machine.module.user.entity.User"*/-->
<!--/*@thymesVar id="user" type="com.xmlan.machine.module.user.entity.User"*/-->
<!--/*@thymesVar id="roleList" type="java.util.List<com.xmlan.machine.module.role.entity.Role>"*/-->
<!--/*@thymesVar id="token" type="java.lang.String"*/-->
<!--/* </editor-fold> */-->

<body>
<th:block th:include="/common/header::header('user')"/>

<main style="z-index: 0;">
  <div class="page-title z-depth-1 blue-grey darken-2">
    <div class="white-text">
      <span class="flow-text">
        <a class="btn-flat tooltipped" data-position="bottom" data-delay="50" data-tooltip="返回列表"
           onclick="history.go(-1);"><i class="material-icons white-text">arrow_back</i></a><span
          th:text="${user.id==newEntityID?'新增用户':user.username}"></span>
      </span>
    </div>
  </div>
  <br/>
  <div id="main-content" class="container">
    <form th:action="@{${adminPath}+'/user/save/'+${user.id}}" method="post" onsubmit="return save();">
      <input name="token" th:value="${token}" type="hidden"/>
      <input id="id" name="id" type="hidden" th:value="${user.id}" class="validate" required="required"/>

      <div class="row">
        <div class="input-field col s6 m3 l3">
          <i class="material-icons prefix">assignment_ind</i>
          <input id="username" name="username" th:value="${user.username}" type="text" class="validate"
                 placeholder="输入用户名" required="required"/>
          <label for="username">用户名</label>
        </div>
        <div class="input-field col s6 m3 l3">
          <i class="material-icons prefix">account_circle</i>
          <input th:if="${user.id==newEntityID}" id="authname" name="authname" th:value="${user.authname}"
                 type="text" class="text" placeholder="输入登录账号" required="required"/>
          <label th:if="${user.id==newEntityID}" for="authname" th:text="登录名"></label>
          <input th:if="${user.id!=newEntityID}" id="authname-ro" name="authname" th:value="${user.authname}"
                 type="text" class="text" readonly="readonly" placeholder="输入登录账号" required="required"/>
          <label th:if="${user.id!=newEntityID}" for="authname-ro" th:text="登录名"></label>
        </div>
        <div class="input-field col s6 m3 l3">
          <i class="material-icons prefix">lock_outline</i>
          <input th:if="${user.id==newEntityID}" id="password" name="password" th:value="${user.password}"
                 type="password" class="text" placeholder="输入登录密码" required="required"/>
          <label th:if="${user.id==newEntityID}" for="password" th:text="登录密码"></label>
          <input th:if="${user.id!=newEntityID}" id="password-ro" name="password" th:value="${user.password}"
                 type="password" class="text" placeholder="输入登录密码" required="required" readonly="readonly"/>
          <label th:if="${user.id!=newEntityID}" for="password-ro" th:text="登录密码"></label>
        </div>
        <div class="input-field col s6 m3 l3">
          <i class="material-icons prefix">lock</i>
          <input th:if="${user.id==newEntityID}" id="confirmPassword" name="confirmPassword" required="required"
                 th:value="${user.password}" type="password" class="text" placeholder="重新确认密码"/>
          <label th:if="${user.id==newEntityID}" for="confirmPassword" th:text="确认密码"></label>
          <input th:if="${user.id!=newEntityID}" id="confirmPassword-ro" name="confirmPassword"
                 th:value="${user.password}" type="password" class="text" placeholder="重新确认密码" required="required"
                 readonly="readonly"/>
          <label th:if="${user.id!=newEntityID}" for="confirmPassword-ro" th:text="确认密码"></label>
        </div>
        <div class="input-field col s12 m3 l3">
          <i class="material-icons prefix">smartphone</i>
          <input id="phone" name="phone" th:value="${user.phone}" type="text" placeholder="输入手机号"/>
          <label for="phone">联系电话</label>
        </div>
        <div class="input-field col s12 m3 l3">
          <i class="material-icons prefix">date_range</i>
          <input th:if="${user.id==newEntityID}" id="addTime" name="addTime" th:value="${user.addTime}" type="text"
                 class="date-picker" placeholder="选择加入时间"/>
          <label th:if="${user.id==newEntityID}" for="addTime" th:text="加入时间"></label>
          <input th:if="${user.id!=newEntityID}" id="addTime-ro" name="addTime" th:value="${user.addTime}" type="text"
                 placeholder="选择加入时间" readonly="readonly"/>
          <label th:if="${user.id!=newEntityID}" for="addTime-ro" th:text="加入时间"></label>
        </div>
        <div class="input-field col s12 m3 l3">
          <i class="material-icons prefix">group</i>
          <select id="roleID" name="roleID">
            <option th:each="item:${roleList}" th:value="*{item.id}" th:text="*{item.name}"
                    th:if="${item.id==user.roleID}" selected="selected"></option>
            <option th:each="item:${roleList}" th:value="*{item.id}" th:text="*{item.name}"></option>
          </select>
          <label for="roleID">所属角色</label>
        </div>
        <div class="input-field col s12 m3 l3">
          <i class="material-icons prefix">assignment_ind</i>
          <input id="founder" name="founder" th:value="${loginUser.username}"  type="text" />
          <label for="founder">创建人:</label>
        </div>
        <div class="input-field col s12 m12 l12">
          <i class="material-icons prefix">place</i>
          <input id="address" name="address" th:value="${user.address}" type="text" class="validate"
                 placeholder="输入地址"/>
          <label for="address">地址</label>
        </div>
        <div class="input-field col s12 m12 l12">
          <i class="material-icons prefix">insert_comment</i>
          <textarea id="remark" name="remark" th:text="${user.remark}" class="materialize-textarea"></textarea>
          <label for="remark">备注</label>
        </div>
      </div>
      <div class="row">
        <div class="input-field col s6 m6 l6 right-align">
          <button type="reset" class="waves-effect waves-light btn"><i class="material-icons left">clear</i>清空</button>
        </div>
        <div class="input-field col s6 m6 l6 left-align">
          <button type="submit" class="waves-effect waves-light btn"><i class="material-icons right">send</i>提交</button>
        </div>
      </div>
    </form>
  </div>
</main>

<th:block th:include="/common/footer::footer"/>
<th:block th:include="/common/script::script"/>
<script type="text/javascript">
  $(function () {
    resize_footer(window.screen.width);
    $(".date-picker").pickadatee({
      closeOnSelect: true
    });
    $("#roleID").material_select();
    toast('[[${message}]]');
  });

  function save() {
    // pass check
    if ($("#password").val() !== $("#confirmPassword").val()) {
      toast("确认密码输入不匹配登录密码");
      return false;
    }
    // Phone validate
    if (!(/^(([+])?(86)(-)?)?1[3|4|5|7|8]\d{9}$/.test($("#phone").val()))) {
      toast("手机号格式不正确");
      return false;
    }
    return true;
  }
</script>
</body>
</html>
